package com.myacg.editor.common.unit.html;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public abstract class Items {
	private Map<String,String> items;
	private String centerSlip;
	private String suffixSlip;
	public Items(String centerSlip,String sufixSlip){
		this.items =new HashMap<>();	
		this.centerSlip = centerSlip;
		this.suffixSlip = sufixSlip;
	}
	public Items(String centerSlip,String sufixSlip,Map<String,String> items){
		this(centerSlip, sufixSlip);	
		Set<String> cssNames = items.keySet();
		for (String name : cssNames) {
			this.items.put(name, items.get(name));
		}
	}
	/**
	 * 向css队列中增加一个样式
	 * @param cssName
	 * @param cssValue
	 * @return
	 */
	public  Items  add(String name,String value){
		if(name!=null && name.length()>0){
//			cssName = cssName.trim();
			this.items.put(name, value);
		}
		return this;
	}
	public  Items  remove(String name){
		if(name!=null && name.length()>0){
			this.items.remove(name);
		}
		return this;
	}
	
	/**
	 * 输出为字符串
	 * @return
	 */
	public   String   print(){
		StringBuffer itemCont = new StringBuffer();
		Set<String> cssNames = this.items.keySet() ; 
		for (String name : cssNames) {
			itemCont.append(this.getItemStr(name)); 
		}
		return  itemCont.toString();
	}
	
	/**
	 * 输出为字符串并且换行
	 * @return
	 */
	public   String   println(){
		StringBuffer itemCont = new StringBuffer();
		Set<String> cssNames = this.items.keySet() ; 
		for (String name : cssNames) {
			itemCont.append(" ");
			itemCont.append(this.getItemStr(name)); 
			itemCont.append("\r\n");
		}
		return  itemCont.toString();
	}
	/**
	 * 获取某一项的html表现形式
	 * @param name
	 * @return
	 */
	public  String getItemStr(String name){
		return " "+name+this.centerSlip+this.items.get(name)+this.suffixSlip+" ";
	}
	/**
	 * 获取某个属性的值
	 * @param name
	 * @return
	 */
	public String getItemValue(String name){
		return  this.items.get(name);
	}
	
	public String getCenterSlip() {
		return centerSlip;
	}
	public void setCenterSlip(String centerSlip) {
		this.centerSlip = centerSlip;
	}
	public String getSuffixSlip() {
		return suffixSlip;
	}
	public void setSuffixSlip(String suffixSlip) {
		this.suffixSlip = suffixSlip;
	}
}
